<?php 
/**
 * ... ...
 * ... ...
 *
 */ 


/**
 * JCAT_UICtrlGtkTree 类型UI控件 ContactList 
 * 
 * @access	public
 * @author	由 JeCat PHP Toolbox 产生 
 */
class ContactList 
	//<<[UnmodifiableBlock.Start]::Extends::>>//
	extends JCAT_UICtrlGtkTree 
	//<<[UnmodifiableBlock.End]::Extends::>>//
{
	/**
	 * ContactList类 的 构造函数 
	 * 
	 * @access	public
	 * @return	void
	 */
	public function ContactList(JCAT_ViewGtk $aParentView)
	{
		$aWidget = $aParentView->GetChildWidget('TreeContactList')  ;
		JCAT_ASSERT::ASSERT_INSTANCE($aWidget,'GtkWidget'
					, JCAT_Language::Sentence('缺少窗体:"%s"','TreeContactList') )  ;
 
		// 初始化 父类 
		$this->JCAT_UICtrlGtkTree(__CLASS__,JCAT_Language::Sentence("*"),$aWidget) ;
	}
	
	/**
	 * 创建一个  GtkTreeModel 模型  
	 * 
	 * @access	public
	 * @return	void
	 */
	public function CreateModel()
	{
		//<<[UnmodifiableBlock.Start]::Create Model::>>//
		$aModel = new GtkTreeStore(
			JCAT_Gtk_TYPE_STRING
			, JCAT_Gtk_TYPE_STRING
			, JCAT_Gtk_TYPE_STRING
			, JCAT_Gtk_TYPE_STRING
			) ;
		//<<[UnmodifiableBlock.End]::Create Model::>>//
		
		// 在此添加代码  
		// TODO ... ...
		
		return $aModel ;
	}
	
	/**
	 * 初始化  GtkTreeView 的列  
	 * 
	 * @access	public
	 * @return	void
	 */
	public function InitializeColumns()
	{
		// 取得视图 
		$wndTreeView = $this->GetMainWidget() ;
		JCAT_ASSERT::ASSERT_INSTANCE($wndTreeView,'GtkTreeView',
					JCAT_Language::SentenceEx('UI控件“%”的主窗体尚未创建，在正常情况下  InitializeColumns()不应该被直接调用，UI控件的主窗体在创建之时，会自动调用此方法。','JCAT',null,$this->GetName())) ;

		// 设置 视图上的 各列 
		//<<[UnmodifiableBlock.Start]::Setting Columns::>>//
		// 视图列：节点类型
		$aRenderForColumn0 = new GtkCellRendererText() ;
		$aRenderForColumn0->set_property('editable',false) ;
		$wndColumn0 = new GtkTreeViewColumn(JCAT_Language::Sentence('节点类型'),$aRenderForColumn0,'text',self::CLM_NODETYPE) ;
		$wndColumn0->set_visible(false) ;
		$wndTreeView->append_column($wndColumn0) ;

		// 视图列：JID
		$aRenderForColumn1 = new GtkCellRendererText() ;
		$aRenderForColumn1->set_property('editable',false) ;
		$wndColumn1 = new GtkTreeViewColumn(JCAT_Language::Sentence('JID'),$aRenderForColumn1,'text',self::CLM_JID) ;
		$wndColumn1->set_visible(false) ;
		$wndTreeView->append_column($wndColumn1) ;

		// 视图列：节点图标
		$aRenderForColumn2 = new GtkCellRendererPixbuf() ;
		$wndColumn2 = new GtkTreeViewColumn(JCAT_Language::Sentence('节点图标'),$aRenderForColumn2,'pixbuf',self::CLM_ICON) ;
		$wndColumn2->set_cell_data_func($aRenderForColumn2,array($this,'OnRenderPixbuf'),self::CLM_ICON) ;
		$wndTreeView->append_column($wndColumn2) ;

		// 视图列：名称
		$aRenderForColumn3 = new GtkCellRendererText() ;
		$aRenderForColumn3->set_property('editable',true) ;
		$aRenderForColumn3->connect('editing-started',array($this,'OnTextEditStarted'),self::CLM_NAME) ;
		$aRenderForColumn3->connect('editing-canceled',array($this,'OnTextEditCanceled'),self::CLM_NAME) ;
		$aRenderForColumn3->connect('edited',array($this,'OnTextEdit'),self::CLM_NAME) ;
		$wndColumn3 = new GtkTreeViewColumn(JCAT_Language::Sentence('名称'),$aRenderForColumn3,'text',self::CLM_NAME) ;
		$wndTreeView->append_column($wndColumn3) ;
		//<<[UnmodifiableBlock.End]::Setting Columns::>>//
		

		// 在此添加 代码 
		// TODO ... ...
		
	}
	
	/**
	 * what's this
	 * 
	 * @access	public
	 * @param	$sCellRenderer		GtkCellRenderer			what's this
	 * @param	$wndEditable		GtkCellEditable			what's this
	 * @param	$sPath				string					what's this
	 * @param	$nColumn=-1		int						what's this
	 * @return	void
	 */
	public function OnTextEditStarted( GtkCellRenderer $sCellRenderer, GtkCellEditable $wndEditable, $sPath, $nColumn=-1 )
	{
		$aModel = $this->GetGtkModel() ;		
		$aItem = $aModel->get_iter_from_string($sPath) ;
		$sItemNodeType = $this->GetCellData($aItem,self::CLM_NODETYPE) ;

		// 联系人
		if( $sItemNodeType!=self::CLM_TYPE_GROUP )
		{
			$sJID = $this->GetCellData($aItem,self::CLM_JID) ;
			$aView = $this->GetParentView() ;
			$sUserNickname = $aView->GetUserNickname(JJ_Account::CreateFromString($sJID)) ;
			$wndEditable->set_text($sUserNickname) ;
		}
		
	}

	/**
	 * what's this
	 * 
	 * @access	public
	 * @param	$aRenderer		GtkCellRendererText		what's this
	 * @param	$sPath			string					what's this
	 * @param	$sNewText		string					what's this
	 * @param	$nColumn		int						what's this
	 * @return	void
	 */
	public function OnTextEdit( GtkCellRendererText $aRenderer , $sPath, $sNewText, $nColumn )
	{
		$aItem = $this->GetItem($sPath) ;
		$sItemNodeType = $this->GetCellData($aItem,self::CLM_NODETYPE) ;
		
		// 联系人
		if( $sItemNodeType!=self::CLM_TYPE_GROUP )
		{
			$sJID = $this->GetCellData($aItem,self::CLM_JID) ;
			$aView = $this->GetParentView() ;
			$sUserNickname = $aView->GetUserNickname(JJ_Account::CreateFromString($sJID)) ;
			$sUserGroupName = $aView->GetUserGroupName(JJ_Account::CreateFromString($sJID)) ;
			
			// 更改 联系人 昵称
			if( $sUserNickname!=$sNewText )
			{
				$aView = $this->GetParentView() ;
				$aMainController = $aView->GetParentController() ;
				$atXMPPConn = $aMainController->GetXMPPConnect() ;
		
				$atXMPPConn->roster_update($sJID,$sNewText,$sUserGroupName) ;
			}
		}
		
		// 联系人 分组
		else
		{
			if($this->bCanEditGroupName)
			{
				parent::OnTextEdit($aRenderer , $sPath, $sNewText, $nColumn) ;
			}
		}
	}
	
	
	
	/**
	 * Description
	 *
	 * @access	public
	 * @param	$bEnable		bool
	 * @return	void
	 */
	public function CanEditGroupName($bEnable)
	{
		$this->bCanEditGroupName = $bEnable ;
	}
	private $bCanEditGroupName = false ;
		
	// 为 视图的列 定义常量 
	//<<[UnmodifiableBlock.Start]::Define Column Consts::>>//
	const CLM_NODETYPE = 0 ;
	const CLM_JID = 1 ;
	const CLM_ICON = 2 ;
	const CLM_NAME = 3 ;
	//<<[UnmodifiableBlock.End]::Define Column Consts::>>//

	const CLM_TYPE_GROUP = 'group' ;
	const CLM_TYPE_CONTACT = 'contact' ;

}






?><?
/**
 * [注意!!]
 *	以下内容由 JCAT PHP Toolbox 自动维护，手动更改的内容会被 JCAT PHP Toolbox 抹除，
 *	同时还可能破坏格式，导致 JCAT PHP Toolbox 无法正常读取。
 */
/*<<[UnmodifiableBlock.Start]::Coder Dialog Data::>>&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&//
<<{{DocumentClass:UICtrlGtkTreeDoc}}>>
eCVEQSVBNSU5M0tvJUQzJTQwJTEwJUM3JUVGSCU3QyU4OCVFRSUxMSU4OTglQjYlRDM2JTVEVyU5NSVDMiUyNiVBOWxiN2klRUQrTiVEMSVFMiUyQyVDRCUyNiU3RUQlRjYlOTY0JThBJTdDJUU5JTA1JTg5JTBBJTg5JTNCJTEyJUUyJUM2JTE1JThFJTA4JTg5byUxMyVDMiVDNyU2MCVENiUwRiVENCU0MCVBNSVGMjgl
QUNkJUNGJUUzJUJGJUJGJTk5JUQ5JUExWCVDMyVBQiUxNDcwalNBJTkxQSVGMSVCRSVGQ1clMEYwJUYyTCUyMiU5MiVDMCUwQyVFNyUwMSUwQlklMjQlREMlRTUlOUMlMjElODNjJUQ1SCUyMSUwNiU5MTglQjglMDglQTNUZjQlRjAlOEElRTMlM0ElN0M0ZWolMTMlMjMlN0YlQzIlODNxJUMyJTIyJ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